home *** CD-ROM | disk | FTP | other *** search
- /*[a-,body+,h-,o=100,r+,rec+,t=4,u+,#+,j=20/57/1$,n-]*/
- /* UMacAppUtilities.p */
- /* Copyright © 1984-1990 Apple Computer, Inc. All rights reserved. */
- /*
- This unit implements a set of simple type declarations and utility
- routines.
- */
- #ifndef __UMacAppUtilities__
- #define __UMacAppUtilities__ 0
- #endif
- #if ! __UMacAppUtilities__
- #define __UMacAppUtilities__ 1
-
- /* • Directive settings to EXPORT */
- #if qDebug
- /*$W-*/
- #else
- /*$W+*/
- #endif
- #if qUnInit
- /*$Init+*/
- #else
- /*$Init-*/
- #endif
- #if qRangeCheck
- /*$R+*/
- /*$OV+*/
- #else
- /*$R-*/
- /*$OV-*/
- #endif
- #if qTrace
- /*$D++*/
- /*$N+*/
- #else
- #if qNames
- /*$D+*/
- /*$N+*/
- #else
- /*$D-*/
- /*$N-*/
- #endif
- #endif
-
- /* • Auto-Include the requirements for this unit's interface. */
- #ifndef __TEXTEDIT__
- #include "TextEdit.h"
- #endif
- #ifndef __FILES__
- #include "Files.h"
- #endif
- #ifndef __TRAPS__
- #include "Traps.h"
- #endif
- #ifndef __SCRAP__
- #include "Scrap.h"
- #endif
- #ifndef __ULoMem__
- #include "ULoMem.h"
- #endif
- /* In the NON-debug case these are set to false and the code they condition will not be
- compiled */
- #if ! qDebug
- const short gPreCondition = false; /* true to do pre-condition processing */
- const short gPostCondition = false; /* true to do post-condition processing */
- #endif
-
- /* set constants from the standard compiletime variables.
- These constants may be used in expressions such that if the expression stati
- cally evaluates
- to false then the compiler will omit conditioned code.
- if NOT qNeedsColorQD THEN
- mumble;
- */
- /*[f-]*/
- /* If for some reason these don't come in from MABuild set them to the highest common fo
- rm
- -NoDebug -System6
- */
- #ifndef qDebug
- #define qDebug 0
- #endif
- #ifndef qDebugTheDebugger
- #define qDebugTheDebugger 0
- #endif
- #ifndef qInspector
- #define qInspector 0
- #endif
- #ifndef qMacApp
- #define qMacApp 1
- #endif
- #ifndef qNames
- #define qNames 0
- #endif
- #ifndef qNeedsColorQD
- #define qNeedsColorQD 0
- #endif
- #ifndef qNeedsFPU
- #define qNeedsFPU 0
- #endif
- #ifndef qNeedsHierarchicalMenus
- #define qNeedsHierarchicalMenus 1
- #endif
- #ifndef qNeedsMC68020
- #define qNeedsMC68020 0
- #endif
- #ifndef qNeedsMC68030
- #define qNeedsMC68030 0
- #endif
- #ifndef qNeedsROM128K
- #define qNeedsROM128K 1
- #endif
- #ifndef qNeedsScriptManager
- #define qNeedsScriptManager 1
- #endif
- #ifndef qNeedsStyleTextEdit
- #define qNeedsStyleTextEdit 1
- #endif
- #ifndef qNeedsWaitNextEvent
- #define qNeedsWaitNextEvent 1
- #endif
- #ifndef qPerform
- #define qPerform 0
- #endif
- #ifndef qRangeCheck
- #define qRangeCheck 0
- #endif
- #ifndef qTemplateViews
- #define qTemplateViews 1
- #endif
- #ifndef qTrace
- #define qTrace 0
- #endif
-
- /* Flag that indicates that the user wants to play around with the new, UNSUPPORTED
- stuff that we on the MacApp team are fiddling with.
- WARNING, Setting this flag true voids your MacApp warranty. It is used to condition
- features that are experimental and UNSUPPORTED. Features enabled with this flag
- may or may not be included in future versions of MacApp and are here for informational
- purposes only.
- 'Nuff said. */
-
- #ifndef qExperimentalAndUnsupported
- #define qExperimentalAndUnsupported 0
- #endif
-
-
- #ifndef __cplusplus /* in C++ the compile variables can be used
- in expressions */
- #if qDebug
- const short qDebug = true;
- #else
- const short qDebug = false;
- #endif
- /* If qDebug then this flag is TRUE else FALSE. */
-
- #if qDebugTheDebugger
- const short qDebugTheDebugger = true;
- #else
- const short qDebugTheDebugger = false;
- #endif
- /* If qDebugTheDebugger then this flag is TRUE else FALSE. */
-
- #if qInspector
- const short qInspector = true;
- #else
- const short qInspector = false;
- #endif
- /* If qInspector then this flag is TRUE else FALSE. */
-
- #if qMacApp
- const short qMacApp = true;
- #else
- const short qMacApp = false;
- #endif
- /* If qMacApp then this flag is TRUE else FALSE. */
-
- #if qNames
- const short qNames = true;
- #else
- const short qNames = false;
- #endif
- /* If qNames then this flag is TRUE else FALSE. */
-
- #if qNeedsColorQD
- const short qNeedsColorQD = true;
- #else
- const short qNeedsColorQD = false;
- #endif
- /* If qNeedsColorQD then this flag is TRUE else FALSE. */
-
- #if qNeedsFPU
- const short qNeedsFPU = true;
- #else
- const short qNeedsFPU = false;
- #endif
- /* If qNeedsFPU then this flag is TRUE else FALSE. */
-
- #if qNeedsHierarchicalMenus
- const short qNeedsHierarchicalMenus = true;
- #else
- const short qNeedsHierarchicalMenus = false;
- #endif
- /* If qNeedsHierarchicalMenus then this flag is TRUE else FALSE. */
-
- #if qNeedsMC68020
- const short qNeedsMC68020 = true;
- #else
- const short qNeedsMC68020 = false;
- #endif
- /* If qNeedsMC68020 then this flag is TRUE else FALSE. */
-
- #if qNeedsMC68030
- const short qNeedsMC68030 = true;
- #else
- const short qNeedsMC68030 = false;
- #endif
- /* If qNeedsMC68030 then this flag is TRUE else FALSE. */
-
- #if qNeedsROM128K
- const short qNeedsROM128K = true;
- #else
- const short qNeedsROM128K = false;
- #endif
- /* If qNeedsROM128K then this flag is TRUE else FALSE. */
-
- #if qNeedsScriptManager
- const short qNeedsScriptManager = true;
- #else
- const short qNeedsScriptManager = false;
- #endif
- /* If qNeedsScriptManager then this flag is TRUE else FALSE. */
-
- #if qNeedsStyleTextEdit
- const short qNeedsStyleTextEdit = true;
- #else
- const short qNeedsStyleTextEdit = false;
- #endif
- /* If qNeedsStyleTextEdit then this flag is TRUE else FALSE. */
-
- #if qNeedsWaitNextEvent
- const short qNeedsWaitNextEvent = true;
- #else
- const short qNeedsWaitNextEvent = false;
- #endif
- /* If qNeedsWaitNextEvent then this flag is TRUE else FALSE. */
-
- #if qPerform
- const short qPerform = true;
- #else
- const short qPerform = false;
- #endif
- /* If qPerform then this flag is TRUE else FALSE. */
-
- #if qRangeCheck
- const short qRangeCheck = true;
- #else
- const short qRangeCheck = false;
- #endif
- /* If qRangeCheck then this flag is TRUE else FALSE. */
-
- #if qTemplateViews
- const short qTemplateViews = true;
- #else
- const short qTemplateViews = false;
- #endif
- /* If qTemplateViews then this flag is TRUE else FALSE. */
-
- #if qTrace
- const short qTrace = true;
- #else
- const short qTrace = false;
- #endif
- /* If qTrace then this flag is TRUE else FALSE. */
-
- #if qExperimentalAndUnsupported
- const short qExperimentalAndUnsupported = true;
- #else
- const short qExperimentalAndUnsupported = false;
- #endif
- /* If qExperimentalAndUnsupported then this flag is TRUE else FALSE. */
-
- #endif
- /*[f+]*/
-
- /* ASCII Character Constants */
- const short chBackspace ='\b'; /* ASCII code for Backspace character */
- const short chClear ='\033'; /* ASCII code for Clear key (aka ESC) */
- const short chDown ='\037'; /* ASCII code for down arrow */
- const short chEnd ='\004'; /* ASCII code for the End key */
- const short chEnter ='\003'; /* ASCII code for Enter character */
- const short chEscape ='\033'; /* ASCII code for Escape (aka Clear) key */
- const short chFunction ='\020'; /* ASCII code for any function key */
- const short chFwdDelete ='\177'; /* ASCII code for forward delete */
- const short chHelp ='\005'; /* ASCII code for Help key */
- const short chHome ='\001'; /* ASCII code for the Home key */
- const short chLeft ='\034'; /* ASCII code for left arrow */
- const short chPageDown ='\f'; /* ASCII code for Page Down key */
- const short chPageUp ='\013'; /* ASCII code for Page Up key */
- const short chReturn ='\n'; /* ASCII code for Return character */
- const short chRight ='\035'; /* ASCII code for right arrow */
- const short chSpace =' '; /* ASCII code for Space character */
- const short chTab ='\t'; /* ASCII code for Tab character */
- const short chUp ='\036'; /* ASCII code for up arrow */
-
- /* Virtual Key Code Constants */
- const short kClearVirtualCode = 71; /* Clear key virtual code */
- const short kEscapeVirtualCode = 53; /* Escape key virtual code */
- const short kF10VirtualCode = 109; /* F10 virtual key code */
- const short kF11VirtualCode = 103; /* F11 virtual key code */
- const short kF12VirtualCode = 111; /* F12 virtual key code */
- const short kF13VirtualCode = 105; /* F13 virtual key code */
- const short kF14VirtualCode = 107; /* F14 virtual key code */
- const short kF15VirtualCode = 113; /* F15 virtual key code */
- const short kF1VirtualCode = 122; /* F1 virtual key code */
- const short kF2VirtualCode = 120; /* F2 virtual key code */
- const short kF3VirtualCode = 99; /* F3 virtual key code */
- const short kF4VirtualCode = 118; /* F4 virtual key code */
- const short kF5VirtualCode = 96; /* F5 virtual key code */
- const short kF6VirtualCode = 97; /* F6 virtual key code */
- const short kF7VirtualCode = 98; /* F7 virtual key code */
- const short kF8VirtualCode = 100; /* F8 virtual key code */
- const short kF9VirtualCode = 101; /* F9 virtual key code */
- const short kFwdDelVirtualCode = 117; /* Forward Delete virtual code */
-
- const short kSysFontName = '\0'; /* GetFontNum converts this to zero. */
- const short kApplFontName = 'A'; /* GetFontNum converts this to one. */
-
- const short kWordAlign = true; /* Constant for OffsetPtr */
- const short kDontAlign = false; /* Constant for OffsetPtr */
-
- const unsigned char kHexDigits[] = "\p0123456789ABCDEF"; /* Digits in base 16 */
-
- const short kNoFileRefnum = - (SHRT_MAX - 1); /* an invalid file refnum; used to indicate
- an unopened file (actually interpreted by
- HFS as a volume number. If you have this
- many volumes you are sick indeed! */
- const short kNoStaticLink = - 1; /* Pascal functions and procedures can take
- "procedure" parameters which are like C++
- function pointers with the additional
- capabilitly to access upscope variables.
- This is particularly convenient for "call
- back" type procedures because they are
- executed in their original scope. Well
- kids, C++ has no equivalent structure, so
- all of the interfaces that call for a
- "procedure" parameter have been translated
- to a function pointer and a static link
- (upscope variable accessor) in the C++
- headers. The static link can be used to
- pass any useful context information
- around, see the C++ examples. HOWEVER,
-
- when a static link is not used or
- required; C++ users must insert a non-NIL
- placeholder. The receiving code is in
- pascal and includes special detection of
- the case where NIL is passed for static
- link. When NIL is passed in, >>> NO <<<
- static link will be passed to the
- "procedure" parameter when it is called!
- You can imagine the ensuing heartache for
- well meaning C++ users as their stack gets
- tromped. The answer, my friends is to have
- C++ users pass kNoStaticLink when they
- don't wish to use the static link. */
-
- /* Field types for the Fields methods. These are understood by StdFieldToString.
- Negative values are reserved for MacApp.
- */
- const short bBoolean = - 1;
- const short bByte = - 2;
- const short bChar = - 3;
- const short bClass = - 4;
- const short bCmdNumber = - 5;
- const short bCntlAdornment = - 6;
- const short bControlHandle = - 7;
- const short bDouble = - 8; /* SANE Double */
- const short bExtended = - 9; /* SANE Extended */
- const short bFixed = - 10;
- const short bFontName = - 11;
- const short bGrafPtr = - 12;
- const short bHandle = - 13;
- const short bHexInteger = - 14;
- const short bHexLongInt = - 15;
- const short bHighByte = - 16;
- const short bHLState = - 17;
- const short bIDType = - 18;
- const short bInteger = - 19;
- const short bLongInt = - 20;
- const short bLowByte = - 21;
- const short bObject = - 22;
- const short bOSType = - 23;
- const short bPattern = - 24;
- const short bPoint = - 25;
- const short bPointer = - 26;
- const short bReal = - 27; /* Pascal Real */
- const short bRect = - 28;
- const short bResType = - 29;
- const short bRGBColor = - 30;
- const short bRgnHandle = - 31;
- const short bSingle = - 32; /* SANE Single */
- const short bSizeDeterminer = - 33;
- const short bString = - 34;
- const short bStringHandle = - 35;
- const short bStyle = - 36;
- const short bTEHandle = - 37;
- const short bTitle = - 38;
- const short bVCoordinate = - 39;
- const short bVPoint = - 40;
- const short bVHSelect = - 41;
- const short bVRect = - 42;
- const short bWindowPtr = - 43;
-
- #if 0 /* !!! can't fieldtostring for multiline
- structures yet (2.0)*/
- const short bTextStyle = - 44;
- const short bConfigRec = - 45;
- const short bScrapStuff = - 46;
- #endif
- const short kMANameSize = 63; /* Maximum size string supported for an
- MAName */
-
- const short kAutoWrap = true; /* Want to AutoWrap (for MATextBox)*/
- const short kNoAutoWrap = ! kAutoWrap; /* Don't want to AutoWrap (for MATextBox)*/
- const short kEraseFirst = true; /* Want to erase first (for MATextBox)*/
- const short kNoEraseFirst = ! kEraseFirst;
- /* Don't want to erase first (for MATextBox)*/
- const short kSpaceForCaret = true;
- /* Want to leave space for an insertion caret
- (for MATextBox)*/
- const short kNoSpaceForCaret = ! kSpaceForCaret;
- /* Don't want to leave space for an insertion
- caret (for MATextBox)*/
- const short teJustSystem = teJustLeft; /* teJustLeft really means use the system
- justification set by the installed script.
- in Arabic and Hebrew systems thi
- s is typically
- right justification (but user changeable).
- using a constant with a better name like
- teJustSystem helps to make this issue more
- visible to the developer. If LEFT
- justification is REQUIRED there
- is of course,
- teForceLeft. */
- /* Some handy types */
- /* MacApp used to indicate the pointer datatype by prepending the type name with a "P"
- and a handle datatype by prepending the type name with a "H". In order to be more
- compatible with the standards used in the toolbox interfaces we will now ind
- icate pointer
- datatypes by appending "Ptr" to the typename and handle datatypes by appendi
- ng "Handle" to
- the typename. The old style names are left in for compatibility in Release 2.0 */
-
- typedef short *IntegerPtr; /* Preferred */
- typedef IntegerPtr *IntegerHandle; /* Preferred */
-
- typedef long *LongIntPtr; /* Preferred */
- typedef LongIntPtr *LongIntHandle; /* Preferred */
-
- typedef Boolean *BooleanPtr; /* Preferred */
- typedef BooleanPtr *BooleanHandle; /* Preferred */
-
- typedef SignedByte *SignedBytePtr; /* Preferred */
- typedef SignedBytePtr *SignedByteHandle; /* Preferred */
-
- typedef IntegerPtr PInteger; /* Left in for compatibility (2.0) */
- typedef IntegerHandle HInteger; /* Left in for compatibility (2.0) */
- typedef LongIntPtr PLongInt; /* Left in for compatibility (2.0) */
- typedef LongIntHandle HLongInt; /* Left in for compatibility (2.0) */
- typedef BooleanPtr PBoolean; /* Left in for compatibility (2.0) */
- typedef SignedBytePtr PByte; /* Left in for compatibility (2.0) */
-
- typedef unsigned char String8[9];
-
- typedef unsigned char MAName[64]; /* A Name in MacApp®. ClassNames,
-
- MethodNames, IVar Names, ProcNames, etc.
- ??? Should we punt on stringlength and
- only define pointers to these strings? */
- typedef StringPtr *MANamePtr; /* Preferred */
- typedef StringPtr **MANameHandle; /* Preferred */
- typedef StringPtr *PMAName; /* Left in for compatibility (2.0) */
- typedef MANameHandle HMAName; /* Left in for compatibility (2.0) */
-
- typedef ResType IDType; /* MacApp uses four byte "signatures" in
- several places. They are a handy way to
- have a partially human readable quantity
- that only takes up a long. */
-
- /* Draw drop shadows against framed selections */
- const unsigned char adnLineTop = (1<<0);
- const unsigned char adnLineLeft = (1<<1);
- const unsigned char adnLineBottom = (1<<2);
- const unsigned char adnLineRight = (1<<3);
- const unsigned char adnDummy = (1<<4);
- const unsigned char adnOval = (1<<5);
- const unsigned char adnRRect = (1<<6);
- const unsigned char adnShadow = (1<<7);
-
- typedef unsigned char CntlAdornment;
-
- typedef long VCoordinate; /* VCoordinates are 32 bits as compared to QD
- Coordinates which are 16 bits */
-
- struct VPoint {
- VCoordinate v, h;
- pascal void IPoint(VCoordinate ah, VCoordinate av) { v=av; h=ah; };
- };
-
- struct VRect {
- VCoordinate top,left,bottom,right;
- pascal void IRect(VCoordinate atop, VCoordinate aleft, VCoordinate abottom, VCoordinate aright)
- { top=atop; left=aleft; bottom=abottom; right=aright; };
- };
-
- struct ConfigRecord { /* ??? should this be PACKED ??? if so, how
- will this affect C++ users? */
- /* Values from SysEnvirons (Version 1) */
- short environsVersion;
- short machineType;
- short systemVersion;
- short processor;
- Boolean hasFPU;
- Boolean hasColorQD;
- short keyboardType;
- short atDrvrVersNum;
- short sysVRefNum;
- /* Derived values */
- Boolean hasROM128K; /* ROM 128K - OR - Better */
- Boolean hasHFS;
-
- Boolean hasHierarchicalMenus;
- Boolean hasScriptManager;
- Boolean hasStyleTextEdit;
- Boolean hasSoundManager;
- Boolean hasWaitNextEvent;
- Boolean hasSCSI;
- Boolean hasDesktopBus;
- Boolean hasAUX;
- Boolean hasTempMem; /* TRUE if Multifinder™ temp memory is avail
- */
- Boolean has32BitQD; /* TRUE if 32 bit Quickdraw is installed */
- };
-
- #if qDebug
- extern pascal Boolean gPreCondition; /* true to do pre-condition processing */
- extern pascal Boolean gPostCondition; /* true to do post-condition processing */
- #endif
- extern pascal short gApplicationRefNum; /* RefNum of the application's res file. */
- extern pascal ConfigRecord gConfiguration; /* The _actual_ environment configuration */
- extern pascal short gMBarHeight; /* Height of the menu bar in pixels */
-
- extern pascal unsigned char gBoolString[2][6]; /* Used to display boolean values. */
- /*$Push*/ /*$J+*/
- extern pascal Ptr GFIELDTOSTRRTN;
- /* Routine that converts fields to strings. */
- /*$Pop*/
-
- /*$Push*/ /*$J+*/
- extern pascal Boolean gToolBoxInitialized; /* Indicates whether toolbox has been inited
- */
- extern pascal Boolean gUDialogInitialized; /* Indicates whether UDialog has been inited
- */
- extern pascal Boolean gUGridViewInitialized; /* Indicates whether UGridView has been
- inited */
- extern pascal Boolean gUPrintingInitialized; /* Indicates whether UPrinting has been
- inited */
- extern pascal Boolean gUTEViewInitialized; /* Indicates whether UTEView has been inited
- */
- extern pascal Ptr gStrippedAddress; /* an address already stripped by
- StripAddress */
- /*$Pop*/
-
- extern pascal RGBColor gRGBBlack, /* RGB representation for black. */
- gRGBWhite; /* RGB representation for white. */
- extern pascal RgnHandle gCursorRgn; /* the current cursor region that will be
- passed to WaitNextEvent as the sleep
- region */
- extern pascal Boolean gDeadStripSuppression; /* Dynamically set to false. Condition the
- execution of a New(aTFoo) to suppress the
- dead-stripping of support for a TFoo */
- extern pascal Boolean gCreateWithTemplates;
- /* Same as gDeadStripSuppression. Left in for
- compatibility (2.0) */
-
- extern pascal TEHandle gMATextBoxTE; /* a working TEHandle for use exclusively by
- MATextBox. Keeps us from having to
- continually allocate and dispose a TE
- (like TextBox does) */
-
- extern pascal Ptr gTEDefaultWordBreak;
- /* The default word break routine used by TE.
- NOTE that _this_ routine (alone) does not
- take parameters using the Pascal calling
- conventions as required by SetWordBreak
- (Thank you TE!) and must be set in the TE
- by munging (Rhymes with plunging) the
- wordBreak field directly. */
-
- /* S T A R T U P U T I L I T I E S */
-
- extern pascal void InitToolBox(void);
- /* Essential toolbox and utility initialization. */
-
- extern pascal void DefineConfiguration(ConfigRecord *configuration);
- /* Fills the configuration record for the host machine. */
-
- extern pascal Boolean ValidateConfiguration(ConfigRecord *configuration);
- /* FALSE if compiled configuration doesn't match runtime config */
-
- /* M I S C E L L A N E O U S U T I L I T I E S */
-
- /* >>> NOTE <<<
- Use the following accessors _wisely_ since they can play real havoc with inter-language
- portability. These routines used to begin with %_ but, that was dropped since it translates
- into the reserved __ in C++.
- */
-
- pascal long GetParmBlockPtr(void)
- = 0x2E88; /* MOVE.L A0,(A7) */
- /* Formerly, %_GetA0. Return the value of register A0. Useful for getting the pointer
- to the parameter block from a VBL task or a completion routine. */
-
- pascal long GetA5(void)
- = 0x2E8D; /* MOVE.L A5,(A7) */
- /* Formerly, %_GetA5. Return the value of register A5. Useful for getting the immediate
- value
- of A5 which is not always the same as CurrentA5. Generally a pointer to the program's
- global area and jump table. */
-
- pascal Ptr GetCurStackFramePtr(void)
- = 0x2E8E; /* MOVE.L A6,(A7) */
- /* Formerly, %_GetA6. Return the value of register A6. Usually a pointer to the local stack
- frame. Most often used to find out the caller's name when invoking a debugging routine. */
-
- pascal Ptr GetCurStackTop(void)
- = 0x2E8F; /* MOVE.L A7,(A7) */
- /* Formerly, %_GetA7. Return the value of register A7. Usually the top of stack. Useful
- for stack sniffing (not a crime). */
-
- /*--------------------------------------------------------------------------------------
- ------*/
-
- extern pascal void BlockSet(Ptr destPtr, long byteCount, SignedByte setVal);
- /* Sets a block of memory to a value. */
-
- extern pascal void CenterRectOnScreen(Rect *aRect, Boolean horizontally, Boolean vertically, Boolean
- forDialog);
- /* Horizontally and/or vertically centers the given rectangle on the main screen. If for
- Dialog
- is true then the rect is vertically centered closer to the top of the screen as for a modal
- dialog. */
-
- extern pascal short CompareStrings(StringPtr first, StringPtr second);
- /* Returns -1, 0, or 1 if first <, =, or > second. */
-
- extern pascal void CopyStr255(StringPtr fmStr, void *toAddr);
- /* Copies a string, copying ONLY what's necessary */
-
- extern pascal void EachWMgrWindowDo(pascal void (*DoToWMgrWindow)(GrafPtr theWMgrWindow, void *
- DoToWMgrWindow_StaticLink), void *DoToWMgrWindow_StaticLink);
- /* Calls DoToWMgrWindow for each window in the windowlist starting at FrontWindow. */
-
- extern pascal GrafPtr FindWindowBefore(GrafPtr theWindow);
- /* returns the window just before a given window. Returns nil if the given window is fro
- ntmost
- or not found. */
-
- pascal Ptr PRStr(StringPtr astr)
- = 0x2E9F; /* Move.L (A7)+,(A7) */
- /* For brain-damaged compiler, which can't pass the address of a string in a packed record,
-
- even though it has to be byte-aligned by definition. Sure, maybe it's not word a
- ligned, but for a
- BlockMove we don't care. When calling CopyStr255 where the destination is the address of a
- Str255 in a packed record, call it like this: CopyStr255(fromStr, PRStr(packedStr)); */
-
- pascal StringPtr AtStr(StringPtr astr)
- = 0x2E9F; /* Move.L (A7)+,(A7) */
- /* Lets you take the address of a string constant so you can pass pointers with no stack
- copy.
- Use it like this: AtStr('Foo'); */
-
- pascal StringPtr *AtMAName(StringPtr astr)
- = 0x2E9F; /* Move.L (A7)+,(A7) */
- /* Lets you take the address of a string constant so you can pass pointers with no stack
- copy.
- Use it like this: AtMAName('Bar'); */
-
- extern pascal void PullApplicationToFront(void);
- /* Applications don't start as the frontmost layer under MultiFinder™. They come to the
- front
- after a few Event calls. If you have a splash screen at startup then you probably want to
- use this call. */
-
- extern pascal void DefaultSize(short *theSize);
- /* If theSize is equal to the system font size then theSize is set to zero. Otherwise it is
- left unchanged. The purpose of this routine is to convert a font size to portable form,
-
- where a font size of zero is the portable equivalent to the system font size. */
-
- extern pascal void *DisposeIfHandle(void *aHandle);
- /* Disposes the handle only if it is non-NIL.
- Returns NIL for convenient assignment back to the reference passed in. */ /* Preferred */
-
- extern pascal void *DisposeIfPtr(void *aPtr);
- /* Disposes the pointer only if it is non-NIL.
- Returns NIL for convenient assignment back to the reference passed in. */ /* Preferred */
-
- extern pascal void DisposIfHandle(void *aHandle); /* Left in for compatibility (2.0) */
-
- extern pascal void DisposIfPtr(void *aPtr); /* Left in for compatibility (2.0) */
-
- extern pascal Boolean EqualBlocks(void *first, void *second, short theSize);
- /* Returns true if the two blocks pointed at by first and second are equal over theSize
- bytes.*/
-
- extern pascal void FieldToString(Ptr theData, short fieldType, StringPtr theString);
- /* Calls the routine whose address is stored in gFieldToStrRtn. Its purpose is to take some
- data pointed to by theData, and whose type is indicated by field type, and convert that
- data into a string representation. By default, gFieldToStrRtn points to StdFieldToString. */
-
- extern pascal short GetActualJustification(short justification);
- /* If the justification passed in is teJustSystem then returns teJustLeft or teJustRight
- depending on the setting of the system justification. Other justifications are just passed
- through to the result. */
-
- extern pascal short GetFontNum(StringPtr fontName);
- /* Returns the font number corresponding to the given name. If fontName is equal to
- kSysFontName then zero is returned. If fontName is equal to kApplFontName then 1 is
- returned. Otherwise the Toolbox routine GetFNum is called to get the font number. */
-
- extern pascal SignedByte GetHandleBits(Handle h);
- /* Return the flag byte of a handle. Left in for compatibility (2.0) */
-
- #if ! qNeedsColorQD
-
- extern pascal void GetIfColor(RGBColor *aColor);
- /* If flag qNeedsColorQD is FALSE then use this method, otherwise use the one below. */
- #else
-
- pascal void GetIfColor(RGBColor *aColor)
- = {0xaa19/* _GetForeColor*/};
- #endif
- /* Fetches current foreground color. Works for both old and new QuickDraw. */
-
- #if ! qNeedsColorQD
-
- extern pascal void GetIfBkColor(RGBColor *aColor);
- /* If flag qNeedsColorQD is FALSE then use this method, otherwise use the one below. */
- #else
-
- pascal void GetIfBkColor(RGBColor *aColor)
- = {0xaa1a/* _GetBackColor*/};
- #endif
- /* Fetches current background color. Works for both old and new QuickDraw. */
-
- extern pascal void GetPortTextStyle(TextStyle *theTextStyle);
- /* Returns the textStyle representing the current state of thePort. */
-
- extern pascal void GetPortFontInfo(short fontNum, StringPtr fontName, short *fontSize);
- /* Returns the font name corresponding to a given name, in portable format. i.e. if font
- Num is
- the system font then kSysFontName is returned; if fontNum is the application font then
- kApplFontName is return; otherwise the Toolbox routine GetFontName is called to get the
- font name. Then, if fontNum is the system or application font, a 0 is returned if the size
- is the default size. */
-
- extern pascal TrapType GetTrapType(short theTrap);
- /* Returns the trap's type (OSTrap or ToolTrap). */
-
- pascal long IntMultiply(short x, short y)
- = {0x301F, /* MOVE.W (A7)+,D0 */
- 0xC1DF, /* MULS.W (A7)+,D0 */
- 0x2E80}; /* MOVE.L D0,(A0) */
- /* Multiplies two integers and returns a longint result. Note that the Pascal compiler will
- generate a 16-bit result if you say n := x * y, truncating the upper 16-bits. Furthermore,
-
- if either x or y is a longint then the compiler expands both operands to 32-bits and calls
- a 32-bit multiply subroutine. IntMultiply avoids these problems. */
-
- extern pascal Boolean IsHandle(void *h);
- /* Returns true or false for handlehood of h */
-
- extern pascal Boolean IsHandleLocked(void *h);
- /* Returns lockState of h */
-
- #if qDebug
-
- extern pascal Boolean IsHandlePurged(void *h);
- /* Returns purgeState of h */
- #else
-
- pascal Boolean IsHandlePurged(void *h)
- = {0x205F, /* MOVE.L (A7)+,A0 */
- 0x4A90, /* TST.L (A0) */
- 0x57D7, /* SEQ (A7) */
- 0x4417}; /* NEG.B (A7) */
- /* Returns purgeState of h */
- #endif
-
- extern pascal short LengthRect(Rect *r, VHSelect vhs);
- /* If vhs is v, returns the length of r; else returns the width of r. */
-
- extern pascal void LockHandleHigh(Handle h);
- /* Convenience function. Moves a handle high (MoveHHi) and locks it (HLock). The two
- operations are very frequently performed together thus, this procedure. Ignores NIL
- handles. */
-
- extern pascal VHSelect LongerSide(Rect *r);
- /* Return an indication of which side is longer. */
-
- extern pascal void LIntToHex(long decNumber, StringPtr hexNumber, short noOfDigits);
- /* LIntToHex converts decNumber to a hexidecimal string of noOfDigits length. */
-
- extern pascal short MAUseResFile(short refNum);
- /* Like the ToolBox UseResFile but, it also returns the old CurResFile setting */
-
- extern pascal void MATextBox(Ptr text, long itsLength, Rect *box, short itsJust, Boolean autoWrap,
- Ptr wordBreak, Boolean eraseFirst, Boolean spaceForCaret);
- /* Like the toolbox TextBox but, it also gives you control over whether the text should
- word-wrap with autoWrap, whether the box should be erased first with eraseFirst and, if
- word-wrap is specified, where the word breaks should be with wordBreak (pass NIL to use
- the default word-wrap routine in TE. Since TextBox uses TE to image the text,
-
- spaceForCaret lets us adjust the drawn text by 1 pixel (the insertion caret) on the left and
- right. If the text is editable or could become editable (as in TEditText) you probably want
- to leave space for a caret. If the text is a title or something then you probably don't
- want to leave space for a caret.*/
-
- extern pascal void MADrawString(StringPtr s, Rect *box, short justification);
- /* A convenience routine. Like the toolbox DrawString but, it uses a StringPtr to help
- reduce stack space requirements. And It also gives you control over
- the bounds into which the text will be drawn and draws it in the correct international
- direction. This routine is _MUCH_ slower than DrawString. */
-
- pascal long Max(long a, long b)
- = {0x201F, /* MOVE.L (A7)+,D0 */
- 0x2E9F, /* MOVE.L (A7)+,(A7) */
- 0xB097, /* CMP.L (A7),D0 */
- 0x6F02, /* BGE.S *+4 */
- 0x2E80}; /* MOVE.L D0,(A7) */
- /* Returns the maximum of a and b. */
-
- pascal long Min(long a, long b)
- = {0x201F, /* MOVE.L (A7)+,D0 */
- 0x2E9F, /* MOVE.L (A7)+,(A7) */
- 0xB097, /* CMP.L (A7),D0 */
- 0x6C02, /* BLE.S *+4 */
- 0x2E80}; /* MOVE.L D0,(A7) */
- /* Returns the minimum of a and b. */
-
- extern pascal long MinMax(long MinVal, long expression, long MaxVal);
- /* Returns the expression bounded by minimum and maximum */
-
- extern pascal void NumberToHex(long theNumber, StringPtr hexString, short hexDigits);
- /* Converts theNumber to a hex string preceeded with '$'.*/
-
- extern pascal long PinOnRect(Rect *theRect, Point thePt);
- /* Like PinRect except that if thePt.h (or v) is >= theRect.right (bottom) it returns
- theRect.right (bottom). PinRect returns 1 less than that except if thePt is exactly on the
- edge of theRect.*/
-
- extern pascal long StripLong(void *address);
- /* same function as the glue/trap stripAddress only the types are long and modified to b
- ypass
- the inefficient MPW glue!!. If inlines could reference relocatables it could ev
- en be inline. */
-
- extern pascal void PointerToHex(long theNumber, StringPtr hexString, short hexDigits);
- /* If theNumber is zero, then hexString is set to 'Nil'. Else theNumber is converted to
- a hex
- string preceeded with '$'.*/
-
- extern pascal Boolean RectsNest(Rect *outer, Rect *inner);
- /* Determine if inner nests within outer. */
-
- extern pascal Boolean VRectsNest(VRect *outer, VRect *inner);
- /* Determine if inner nests within outer for VCoordinates. */
-
- extern pascal long RoundUp(long aNumber, short aModulus);
- /* Rounds aNumber up so that it is evenly divisible by aModulus. */
-
- extern pascal short SetKeyScript(short newKeyScript);
- /* If newKeyScript is different from the current key script, then the key script is set to
- newKeyScript. (The reason we don't want to set the key script to the same thing is that the
- Script Mgr. does a FlushEvents when it sets the key script.) */
-
- extern pascal void SetHandleBits(Handle h, SignedByte theBits);
- /* Sets the flag byte of a handle. Left in for compatibility (2.0) */
-
- #if ! qNeedsColorQD
-
- extern pascal void SetIfColor(const RGBColor *aColor);
- /* If flag qNeedsColorQD is FALSE then use this method, otherwise use the one below. */
- #else
-
- pascal void SetIfColor(const RGBColor *aColor)
- = {0xaa14/* _RGBForeColor*/};
- #endif
- /* Sets foreground color. Works for both old and new QuickDraw. */
-
- #if ! qNeedsColorQD
-
- extern pascal void SetIfBkColor(const RGBColor *aColor);
- /* If flag qNeedsColorQD is FALSE then use this method, otherwise use the one below. */
- #else
-
- pascal void SetIfBkColor(const RGBColor *aColor)
- = {0xaa15/* _RGBBackColor*/};
- #endif
- /* Sets background color. Works for both old and new QuickDraw. */
-
- extern pascal void SetPortTextStyle(TextStyle *theTextStyle);
- /* Sets the font style of the current port to the characteristics of theTextStyle. */
-
- extern pascal void SetRGBColor(RGBColor *RGB, short red, short green, short blue);
- /* Sets RGB to the given colors. */
-
- extern pascal void SetTextStyle(TextStyle *theTextStyle, short theFont, unsigned short theStyle,
- short theSize, RGBColor *theColor);
- /* Sets theTextStyle to the given characteristics */
-
- extern pascal void StdFieldToString(Ptr theData, short fieldType, StringPtr theString);
- /* This routine converts all field types defined by the constants in this unit. */
-
- extern pascal void ScrapStuffFields(StringPtr aTitle, ScrapStuff *aScrapStuff, pascal void (*
- DoToField)(StringPtr fieldName, Ptr fieldAddr, short fieldType, void *DoToField_StaticLink), void
- *DoToField_StaticLink);
- /* Used to inspect the fields of a ScrapStuff. */
-
- extern pascal void TextStyleFields(StringPtr aTitle, TextStyle *aStyle, pascal void (*DoToField)(
- StringPtr fieldName, Ptr fieldAddr, short fieldType, void *DoToField_StaticLink), void *
- DoToField_StaticLink);
- /* Used to inspect the fields of a TextStyle record. */
-
- extern pascal void ConfigRecFields(StringPtr aTitle, ConfigRecord *aConfigRec, pascal void (*
- DoToField)(StringPtr fieldName, Ptr fieldAddr, short fieldType, void *DoToField_StaticLink), void
- *DoToField_StaticLink);
- /* Used to inspect the fields of a Config record. */
-
- extern pascal Boolean TrapExists(short theTrap);
- /* Returns true if the given trap exists at run-time */
-
- extern pascal short UprChar(short ch);
- /* Returns ch converted to upper case */
-
- extern pascal void UprStr255(StringPtr s);
- /* Converts s to all upper case. */
-
- extern pascal void UprMAName(StringPtr s);
- /* Converts s to all upper case. */
-
- extern pascal short LowerChar(short ch);
- /* Returns ch converted to lower case */
-
- extern pascal void LowerStr255(StringPtr s);
- /* Converts s to all lower case. */
-
- pascal void UseSelectionColor(void)
- = {0x08B8, 0x0007,0x0938/* kLMHiliteMode*/}; /* BCLR #$07,kLMHiliteMode */
- /* Call to make the next (and only the next) QD operation use the selection color. */
-
- extern pascal void UseROMMap(Boolean resLoad);
- /* Call this before any Resource Manager call for which you might like to use ROM resources.
- Remember, if you pass FALSE to this then you should call SetResLoad(TRUE) afterwards. */
-
- extern pascal void WithApplicationResFileDo(pascal void (*DoWithResFile)(void *
- DoWithResFile_StaticLink), void *DoWithResFile_StaticLink);
- /* Performs a proc with the application res file as the curResFile restoring the prev se
- tting
- at completion. */
-
- /* F I L E U T I L I T I E S */
-
- extern pascal OSErr CloseFile(short dataRefnum, short rsrcRefnum);
- /* Closes the data and resource forks of a file. If dataRefnum = kNoFileRefnum then the data
- fork is not closed. Likewise, if rsrcRefnum = kNoFileRefnum then the resource fork is not
- closed. Returns noErr if successful, else an O.S. error. */
-
- extern pascal OSErr DeleteFile(StringPtr namePtr, short volRefnum);
- /* Deletes the specified file; uses FillInDirID to bypass the Poor Man's Search Path. */
-
- extern pascal long FileModDate(StringPtr name, short volRefnum);
- /* Returns file modification date or 0 if an I/O error occurs */
-
- extern pascal OSErr FillInDirID(HParmBlkPtr pb);
- /* Based on the ioVRefnum field of pb^, looks up the dirID of the working directory and
- fills
- it into the ioDirID field. If HFS is not installed, it sets the ioDirID to 0. This is used
- to inhibit the PMSP. After setting up your HParamBLockRec, call this to fill in the dirID
- and then make the H form of the call (eg., PBHGetFInfo rather than PBGetFInfo). */
-
- extern pascal OSErr GetDirID(short *vRefnum, long *dirID);
- /* Returns the dirID corresponding to a given wdRefnum; changes vRefnum to be a real volume
- refnum. */
-
- extern pascal OSErr GetFileInfo(StringPtr name, short volRefnum, HParamBlockRec *info);
- /* Makes a PBHGetFInfo call, and returns result in info. Bypasses PMSP. */
-
- extern pascal long NumBlocks(long numBytes, long blkSize);
- /* Returns the number of blocks required to store numBytes, given that the block size is
- blkSize. */
-
- extern pascal OSErr MAOpenFile(StringPtr name, short volRefnum, Boolean openData, Boolean openRsrc,
- short dataPerm, short rsrcPerm, short *dataRefnum, short *rsrcRefnum);
- /* Open the specified forks of the file using the specified permissions. Returns kNoFile
- Refnum
- for refnums that are not (or cannot) be opened. On 64K ROM machines, rsrcPerm is ignored.
- Returns an O/S error if the data fork does not exist; returns a rsrcRefnum of kNoFileRefnum
- if the resource fork does not exist. Returns an O/S error for all other errors. If no error
- occurs, returns NoErr. */
-
- /* D E B U G G I N G U T I L I T I E S */
-
- extern pascal Str255 ConcatNumber(StringPtr aString, long aNumber);
- /* Returns aString appended with the string representation of aNumber */
-
- extern pascal Boolean CanReadLn(void);
- /* returns TRUE if WritelnWindow is available and the display is not suppressed */
-
- extern pascal Boolean CanWriteLn(void);
- /* returns TRUE if WritelnWindow is available */
-
- extern pascal short ReadInteger(StringPtr prompt);
- /* Displays prompt and reads an integer from the debug window. */
-
- extern pascal Boolean ReadYesNo(StringPtr prompt);
- /* Displays prompt and accepts a 'y' or 'n' as input from the debug
- window. */
-
- extern pascal Boolean VerboseIsHandle(void *h);
- /* Returns true if h is really a handle. If not then it prints diagnostic info about the
- alleged handle. */
-
- extern pascal void WritePt(Point pt);
- /* Writes the point in the debug window. */
-
- extern pascal void WritePtr(long val);
- /* Writes the pointer, in hex, in the debug window. */
-
- extern pascal void WriteRect(Rect *r);
- /* Writes the rectangle in the debug window. */
-
- extern pascal void WriteBoolean(Boolean b);
- /* Writes the boolean in the debug window. */
-
- extern pascal void WriteVPt(VPoint *pt);
- /* Writes the VPoint in the debug window. */
-
- extern pascal void WriteVRect(VRect *r);
- /* Writes the VRect in the debug window. */
-
- extern pascal void WrLblPt(StringPtr aLabel, Point pt);
- /* Writes the label, ' = ', the point, to the debug window. */
-
- extern pascal void WrLblPtr(StringPtr aLabel, long val);
- /* Writes the label, ' = ', the pointer in hex, to the debug window. */
-
- extern pascal void WrLblRect(StringPtr aLabel, Rect *r);
- /* Writes the label, ' = ', the rectangle, to the debug window. */
-
- extern pascal void WrLblBoolean(StringPtr aLabel, Boolean b);
- /* Writes the label, ' = ', the boolean, to the debug window. */
-
- extern pascal void WrLblVPt(StringPtr aLabel, VPoint *pt);
- /* Writes the label, ' = ', the VPoint in the debug window. */
-
- extern pascal void WrLblVRect(StringPtr aLabel, VRect *r);
- /* Writes the lable, ' = ', the VRect in the debug window. */
-
- extern pascal void WriteSig(ResType theID);
- /* Writes out an IDType signature. */
-
- extern pascal void WrLblSig(StringPtr theLabel, ResType theID);
- /* Writes the label, ' =', theID in the debug window. */
-
- extern pascal void WrLblHandleContents(StringPtr aLabel, void *theHandle);
- /* Writes the label, ' =', theHandle in the debug window. */
-
- extern pascal void WriteHandleContents(void *theHandle);
- /* Writes theHandle in the debug window. */
-
- extern pascal void WriteHexInt(short theInt);
- /* Writes theInt in the debug window. */
-
- extern pascal void WrLblHexInt(StringPtr theLabel, short theInt);
- /* Writes the label, ' =', theInt in the debug window. */
-
- extern pascal void WriteHexLongint(long theLongint);
- /* Writes theLongint in the debug window. */
-
- extern pascal void WrLblHexLongint(StringPtr theLabel, long theLongint);
- /* Writes the label, ' =', theLongint in the debug window. */
- #endif
-
-